import random
import time


def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    else:
        pivot = arr[0]
        left = [x for x in arr[1:] if x <= pivot]
        right = [x for x in arr[1:] if x > pivot]
        return quick_sort(left) + [pivot] + quick_sort(right)


# 生成随机数组
random_array = [random.randint(1, 100000) for _ in range(100000)]
# print("随机生成的数组:", random_array)

# 记录开始时间
start_time = time.time()

# 对随机数组进行快速排序
sorted_array = quick_sort(random_array)

# 记录结束时间
end_time = time.time()

# 计算排序所用时间
elapsed_time = end_time - start_time

# print("排序后的数组:", sorted_array)
print(f"快速排序所用时间: {elapsed_time} 秒")